package com.guigu.controller;
import com.guigu.dto.MemberDTO;
import com.guigu.dto.UserDTO;
import com.guigu.entity.role;
import com.guigu.entity.t_account_role;
import com.guigu.service.UserService;
import com.guigu.vo.Result;
import com.guigu.vo.UserVO1;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/user")
public class UserAction {
	@Autowired
	private UserService accountService;

	public void setStudentService(UserService AccountService) {
		this.accountService = AccountService;
	}

	@GetMapping("/queryuser")
	@ResponseBody
	public Result<List<UserVO1>> queryAccount() throws Exception {
		//System.err.println("sdfsa");
		List<UserVO1> userList = this.accountService.query();
		return new Result<>("200", "true", "成功查询用户列表", userList);

	}

	@GetMapping("/role")
	@ResponseBody
	public Result<List<role>> queryrole() throws Exception {
		//System.err.println("sdfsa");
		List<role> roleList = this.accountService.queryrole();
		return new Result<>("200", "true", "成功查询角色列表", roleList);
	}

	@PostMapping("/adduser")
	@ResponseBody
	public Result adduser(@RequestBody  UserDTO dto) throws Exception {
		System.err.println(dto);
		this.accountService.adduser(dto);
		return new Result<>("200", "true", "成功添加用户", null);
	}
	@PostMapping("/updateuser")
	@ResponseBody
	public Result updateuser(@RequestBody  UserDTO dto) throws Exception {
		System.err.println(dto);
        this.accountService.updateuser(dto);
        return new Result<>("200", "true", "成功更新用户", null);
	}
	@PostMapping("/Deluser")
	public Result Del(@RequestBody UserDTO dto){
		this.accountService.Del(dto.getUser_Id());
		return new Result<>("200", "true", "成功删除用户", null);
	}
	@PostMapping("/rolename")
	public Result<List<role>> rolename(@RequestBody UserDTO name){
		System.err.println(name);
		List<role> roleList =this.accountService.rolename(name.getUser_name());
		return new Result<>("200", "true", "成功查询角色用户", roleList);
	}
	@PostMapping("/rolename1")
	public Result<List<role>> rolename1(@RequestBody UserDTO name){
		System.err.println(name);
		List<role> roleList =this.accountService.rolename1(name.getUser_Id());
		return new Result<>("200", "true", "成功查询角色用户", roleList);
	}
	@PostMapping("/quanxainfo")
	public Result quanxainfo(@RequestBody t_account_role name){
		System.err.println(name);
		this.accountService.quanxainfo(name);
		return new Result<>("200", "true", "成功查询角色用户", null);
	}
}
